import { Component } from '@angular/core';
// 引入Parse第三方库
import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")
@Component({
  selector: 'app-subpage-dong',
  templateUrl: './subpage-dong.component.html',
  styleUrls: ['./subpage-dong.component.scss']
})
export class SubpageDongComponent {
  ngOnInit():void{
    this.Sort("东北菜")
  }
  searchByOrder(ev:any,key?:string,type?:string){
    let value = ev.srcElement.options[ev.srcElement.selectedIndex].value
    if(value){
      key = value.split("-")[0]
      type = value.split("-")[1]
    }
    this.Sort(this.currentCate,{
      key:key,type:type
    })
  }
  // 获取主页面下面的食物简介
  foodList:any=[]  
  currentCate:string = "东北菜"
  async Sort(item:any,orderOptions?:{
    key:any,type:any
  }){
    console.log(item);
    let query = new Parse.Query("Goods")
    query.equalTo("cate",item)  // 参考：https://docs.parseplatform.org/js/guide/#basic-queries
    if(orderOptions){
      if(orderOptions.type=="asc"){
        query.ascending(orderOptions.key)
      }
      if(orderOptions.type=="desc"){
        query.descending(orderOptions.key)
      }
    }
    let list = await query.find()
    this.foodList = list 
  }
  
}
